﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Maticsoft.Web.sysMan
{
    public partial class ListSetUp : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();
            }
        }

        private void Bind()
        {
            Maticsoft.BLL.setUpInfo sm = new BLL.setUpInfo();

            List<Maticsoft.Model.setUpInfo> sl = sm.GetModelList("");

            if (sl.Count > 0)
            {
                Maticsoft.Model.setUpInfo s = sl[0];
                this.txtcstartTime.Text = s.startTime.Value.ToShortDateString();
                this.txtendTime.Text = s.endTime.Value.ToShortDateString();
            }
        }

        protected void btn_save_Click(object sender, EventArgs e)
        {
            DateTime startT = DateTime.Parse(this.txtcstartTime.Text);
            DateTime endT = DateTime.Parse(this.txtendTime.Text);

            Maticsoft.BLL.setUpInfo sm = new BLL.setUpInfo();

            List<Maticsoft.Model.setUpInfo> sl = sm.GetModelList("");

            if (sl.Count > 0)
            {
                Maticsoft.Model.setUpInfo s = sl[0];

                s.startTime = startT;
                s.endTime = endT;

                if (sm.Update(s))
                {
                    Maticsoft.Common.MessageBox.Show(this.Page,"保存成功！");
                }
            }
            else
            {
                Maticsoft.Model.setUpInfo s = new Model.setUpInfo ();

                s.startTime = startT;
                s.endTime = endT;

                if (sm.Add(s))
                {
                    Maticsoft.Common.MessageBox.Show(this.Page, "保存成功！");
                }
            }
        }
    }
}